<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" name="" id="input">
</body>
<script>
    let data = {
        name: '软软'
    }
    let kk = ''
    // 数据层改变 视图层也改变
    Object.defineProperty(data, 'name', {
        get() {
            console.log('我被调用了');
            return kk
        },
        set(val) {
            document.getElementById('input').value = val
            console.log('我被修改了', val);
            kk=val
        },
    })
//视图层改变，数据层也改变
    document.getElementById('input').addEventListener('input', e => {        
        data.name        = e.target.value
    })
</script>

</html>